package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.OrderBill;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.serivce.IOrderBillService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("orderBill")
public class OrderBillController {
    @Autowired
    private IOrderBillService orderBillService;

    @RequestMapping("view")
    public String view() throws Exception {
        return "orderBill";
    }

    @RequestMapping("query")
    @ResponseBody
    public PageResult query(QueryObject qo) throws Exception {
        PageResult query = orderBillService.query(qo);
        return query;
    }

    @ResponseBody
    @RequestMapping("delete")
    public JSONResult delete(Long id) throws Exception {
        try {
            orderBillService.deleteByPrimaryKey(id);
            return new JSONResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult().mark("操作失败!");
        }
    }

    @ResponseBody
    @RequestMapping("saveOrUpdate")
    public JSONResult saveOrUpdate(OrderBill orderBill) throws Exception {
        try {
            orderBillService.saveOrUpdate(orderBill);
            return new JSONResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JSONResult().mark("保存失败!");
        }
    }

    @RequestMapping("audit")
    @ResponseBody
    public Object audit(Long id) throws Exception{
        orderBillService.audit(id);
        return new JSONResult();
    }


}
